package com.whoimi.admin.repository;

import com.whoimi.admin.entity.Menu;
import org.springframework.data.jdbc.repository.query.Modifying;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface MenuRepository extends CrudRepository<Menu, Long> {

    Iterable<Menu> findByType(String type);

    List<Menu> findByTypeOrderBySort(String type);

    List<Menu> findByTypeNotContainingOrderBySort(Integer type);
    List<Menu> findAllByOrderBySort();

    List<Menu> findAllByRouteName(String routeName);

    List<Menu> findAllByParentId(Long parentId);

    @Modifying
    @Query("update sys_menu set tree_path = :treePath where parent_id = :parentId")
    Integer updateTreePathByParentId(String treePath, Long parentId);


}